home *** CD-ROM | disk | FTP | other *** search
/ stazsoftware.com / www.stazsoftware.com.tar / www.stazsoftware.com / futurebasic / sample-code / helpProj.sit / Help Project Folder / List Display.INCL < prev    next >
Text File  |  2005-04-15  |  13KB  |  400 lines

  1.  
  2. '~'1
  3. /* 
  4.      "List.INCL" file for Program Generator files
  5.       can be modified for not PG projects
  6.      Adapted for use with FB^3 by David Bailey - dabsoftware.com
  7.      12/29/2002
  8.      Free source code
  9. */
  10. '~'1
  11.  
  12.  
  13. GOTO "EndOfList"
  14.  
  15. BEGIN GLOBALS
  16.  
  17. BEGIN Record ListRecord
  18. DIM as int       ncols'number of colums
  19. dim as long      numRecords'number of records filled in after first drawing
  20. dim as int       STResNo'Using a String Resource in this example
  21. DIM as int       LScrollBtn
  22. DIM as LONG      LScrlBtnMax
  23. dim as rect      ListRect'The overall rectangle for the list
  24. DIM as rect      selrect[20]
  25. DIM as int       colwd%[20]'20 columns each can have their own width
  26. Dim as RGBCOLOR  RGB[20]'each column can have a different color
  27. DIM as INT       txtalign[20]'left = 0, right = 1, center = 2
  28. DIM as int       oldselect'the list row previously selected
  29. dim as int       newselect'the new selection if there is one
  30. dim as int       WhichString'which string in the resouce selected
  31. DIM as INT       buttonsized
  32. dim as int       fnt'the font to use
  33. dim as int       sze'the size to use
  34. dim as int       styl'the style to use
  35. DIM as str255    2 delim$'the delimiting character for each row
  36. DIM as str255    2 icon$'the delim string noting what follows is an icon id and not a string
  37. end record
  38.  
  39.  
  40. '~'4
  41. 'You must dimension one global list record for each list you want to draw
  42. '~'4
  43. DIM HelpList         as ListRecord
  44.  
  45. end globals
  46.  
  47. '~':
  48.  
  49. /*
  50.      This function draws the list using a handle to various data
  51. */
  52. CLEAR LOCAL
  53. dim as rgbcolor   rg
  54. dim as rect       tBox
  55. dim as STR255     t$,delim$,t2$
  56. dim as long       count
  57. dim as RECT       col(20)
  58. dim as int        c,x,y,pt,pt2,numRows,xp,iconwd,err,n
  59. dim as FontInfo   myFontInfo
  60. dim as rgbcolor   hilite
  61. '~'2
  62. local fn DrawList(List AS ^ListRecord)'WhichList)
  63. '~'2
  64. rg.red = 60000
  65. rg.blue = 65000
  66. rg.green = 62000
  67. GetPortHiliteColor (WINDOW(_wndPort),hilite)'to set hilite color
  68. text List.fnt,List.sze,List.styl,_SrcOr'set the font from the record
  69. GetFontInfo(myFontInfo)'get the font infor for placing string with descent
  70.  
  71. col.top(1)    = List.ListRect.top+1'Top of first cell
  72. col.left(1)   = List.ListRect.left+1'Left side of first cell
  73. col.bottom(1) = col.top(1) + USR FONTHEIGHT+1'bottom of first cell
  74. col.right(1)  = col.left(1) + List.colwd[1]'right side of first cell
  75. Long if col.right(1) > List.ListRect.right-1'if we made it too wide
  76. col.right(1) = List.ListRect.right-1'set it to the widest possible
  77. END IF
  78. LONG IF List.ncols = 1'only one column
  79. Long if col.right(1) < List.ListRect.right'we did not set the width correctly
  80. col.right(1) = List.ListRect.right'so set it to the width of the list
  81. END IF'some of this above can be removed if you never pass the incorrect width/num of columns etc
  82. END IF
  83. iconwd = col.bottom(1) - col.top(1)'make any icon cell square
  84.  
  85. LONG IF List.ncols > 1'Loop through the
  86. FOR c = 2 to List.ncols'remaining columns
  87. col(c);8     = @col(1)'and set the left
  88. col.left(c)  = col.right(c-1)-1'and right sides
  89. col.right(c) = col.left(c) + List.colwd[c]'for this column
  90. Long if col.right(c) > List.ListRect.right-1'if what we add up is too wide for the list
  91. col.right(c) = List.ListRect.right-1'set it to the max width
  92. END IF
  93. IF c = List.ncols then col.right(c) = List.ListRect.right-1'if it is the last column set to the edge
  94. NEXT
  95. end if
  96.  
  97. for c = 2 to List.ncols'width modify selection rectangles
  98. setrect(List.selrect[c],col.left(c)-2,col.top(c),col.left(c)+3,col.top(c)+USR FONTHEIGHT+1)
  99. NEXT
  100.  
  101. CLIPRECT(List.ListRect)'only draw within the list
  102. count = button(List.LScrollBtn)'check the current position of the scroll bar
  103. IF count <= 0 then count = 1'if it is the first drawing we many not have a value yet
  104.  
  105. flushwindowbuffer _FBAutoFlushOff
  106.  
  107. PEN 1,1,1,0,3'for a dotted cell border
  108. numRows = ((List.ListRect.bottom-List.ListRect.top)\(USR FONTHEIGHT))'calculate the number of visible rows
  109. FOR y = count TO count + numRows'start with first visible cell and loop
  110. LONG IF y <= List.numRecords
  111. t$ = STR#(List.STResNo,y)'temp string with delim
  112. XELSE
  113. t$ = ""'beyond the end of the list so null the string
  114. END IF
  115. FOR x = 1 to List.ncols'create strings from this for each column
  116. PENNORMAL'reset the pen
  117. 'forecolor(_blackcolor)'set to black to prepare for drawing grid
  118.  
  119. long if y mod 2 = 0'new itunes type color list separation
  120. rgbforecolor(rg)
  121. Paintrect(col(x))
  122. xelse
  123. foreCOLOR(_whitecolor)'get ready to erase
  124. PAINTRECT(col(x))'erase to white - could be any color you want
  125. end if
  126.  
  127. PEN 1,1,1,0,3'for a dotted cell border
  128. forecolor(_blackcolor)
  129. IF x > 1 THEN plot col.left(x),col.top(x) to col.left(x),col.bottom(x)
  130.  
  131. 'FRAMERECT(col(x))'frame the cell
  132. INSETRECT(col(x),1,1)'inset the cell for the text box
  133. CLIPRECT(List.ListRect)'only draw within the list
  134. LONG IF t$ <> ""
  135. long IF x = 1'If its our first pass start with char 0
  136. pt = 0
  137. xelse
  138. pt = pt2'else move to where the first column string ended
  139. end if
  140. pt2 = instr(pt+1,t$,List.delim$)'find the next delim in the string
  141. t2$ =  MID$(t$,pt+1,pt2-pt-1)'parse the cell text between delim
  142.  
  143. IF pt2 = 0 then t$ = ""'if we reached the end the the cell is blank
  144.  
  145. LONG IF List.newselect = y'found our highlighted item
  146. rgbbackcolor(hilite)
  147. rgbforecolor(hilite)
  148. Paintrect(col(x))
  149. rgbforecolor(List.RGB[x])'our individual cell colors!!
  150. xelse
  151. rgbforecolor(List.RGB[x])'our individual cell colors!!
  152. END IF
  153.  
  154. 'backcolor(_whitecolor)
  155. LONG IF LEFT$(t2$,1) = List.icon$'is this an icon id number?
  156. t2$ = RIGHT$(t2$,LEN(t2$)-1)'get the id number of the icon family
  157. n = col.right(x)
  158. col.right(x) = col.left(x) + iconwd
  159. 'err = FN PlotIconID(@col(x), 0, 0, VAL(t2$))'depending on the size of rect ie ics4,icm4 etc
  160. col.right(x) = n
  161. xelse
  162. rgbforecolor(List.RGB[x])'our individual cell colors!!
  163. SELECT List.txtalign[x]
  164. CASE 0'left alignment
  165. moveto(col.left(x)+2,col.bottom(x)-myFontInfo.descent)
  166. drawstring(t2$)
  167. CASE 1'center alignment
  168. xp = col.left(x) + ((col.right(x)-col.left(x))/2) - FN STRINGWIDTH(t2$)/2
  169. moveto(xp,col.bottom(x)-myFontInfo.descent)
  170. drawstring(t2$)
  171. CASE 2'right alignment
  172. xp = col.right(x) - FN STRINGWIDTH(t2$)
  173. moveto(xp,col.bottom(x)-myFontInfo.descent)
  174. drawstring(t2$)
  175. END SELECT
  176. END IF
  177. END IF
  178. INSETRECT(col(x),-1,-1)'reset cell to orig size
  179. offsetrect(col(x),0,USR FONTHEIGHT)'offset to next row
  180. CLIPRECT(List.ListRect)'only draw within the list
  181. NEXT
  182. NEXT
  183. forecolor(_blackcolor)'return color to normal
  184. CLIPRECT(gBigT)'set clip to full
  185. pennormal
  186. FRAMERECT(List.ListRect)'frame the list
  187. LONG IF BUTTON(List.LScrollBtn) = 1' and List.newselect = 0'for this demo say we did not match the scroll button to the list height
  188. SETRECT(tbox,List.ListRect.right,List.ListRect.top,List.ListRect.right + 16,List.ListRect.bottom)
  189. xp = List.numRecords-numRows+1
  190. if xp <= 0 then xp = 1
  191. SCROLL BUTTON List.LScrollBtn,,,xp,,@tbox'you could put this in PG and then just resize it
  192. END IF
  193. flushwindowbuffer _FBAutoFlushOn
  194. end fn
  195.  
  196.  
  197. CLEAR LOCAL
  198. DIM as handle btnHndl&
  199. dim as rect   tbox
  200. dim as int    x,WhichString,err,oldsel,newsel,top,j,numRows,BtnMax,CurRes,drawList
  201. DIM as point  mPt
  202. DIM as EventRecord evnt
  203. DIM as str255  Selected$
  204. '~'2
  205. LOCAL FN DoListSelecton$(List AS ^ListRecord)'pass which list we clicked
  206. '~'2
  207. text List.fnt,List.sze,List.styl,_srcOr'set to proper font
  208. numRows = (List.ListRect.bottom-List.ListRect.top)\(USR FONTHEIGHT)'set the number of rows depending on the font size
  209. WHILE FN BUTTON'set the first row to a temp selection rectangle
  210. setrect(tbox,List.ListRect.left+1,List.ListRect.top+1,List.ListRect.right-1,List.ListRect.top+USR FONTHEIGHT)
  211. x = 1'verticle row counter
  212. drawList = _FALSE'set to false for each loop beginning
  213. DO
  214. getmouse(mPt)'get the mouse location
  215. LONG IF FN PTINRECT(mPt,tbox)'is it in THIS row?
  216. newsel = x'Set the new selection to this row
  217. LONG IF oldsel <> newsel'check to see if it is not already selected
  218. LONG IF List.LScrollBtn
  219. List.newselect = x + BUTTON(List.LScrollBtn) - 1'Set the list record selected row variable
  220. XELSE
  221. List.newselect = x
  222. END IF
  223. drawList = _TRUE
  224. oldsel = x'make this the OLD selection now
  225. END IF
  226. EXIT DO'Exit the loop cuz we found the selection
  227. XELSE
  228. OFFSETRECT(tbox,0,USR FONTHEIGHT)'not the selected cell - offset and try again
  229. END IF
  230. LONG IF List.LScrollBtn > 0
  231. SELECT
  232. CASE mPt.v% < List.ListRect.top'mouse clicked in list and dragged above
  233. LONG IF BUTTON(List.LScrollBtn) > 1 or List.newselect > 1'only if the button has room to move up
  234. LONG IF List.newselect < BUTTON(List.LScrollBtn) + 1
  235. scroll BUTTON List.LScrollBtn,BUTTON(List.LScrollBtn)-1'step the button one place
  236. end if
  237. LONG iF List.newselect > 1'only if selection is not the top row
  238. List.newselect = List.newselect -1
  239. END IF'set selection up one place
  240. drawList = _TRUE
  241. EXIT DO'Exit the loop cuz we found the selection
  242. END IF
  243. CASE mPt.v% > List.ListRect.bottom'same as above except we drag down here
  244. LONG IF List.newselect < List.numRecords
  245. LONG IF List.newselect > BUTTON(List.LScrollBtn) + numRows-2'scroll selected line until it reaches the bottom
  246. scroll BUTTON List.LScrollBtn,BUTTON(List.LScrollBtn)+1'then start moving the scroll bar
  247. END IF
  248. LONG IF List.newselect < List.numRecords'if not at the bottom increment the item to show
  249. List.newselect = List.newselect +1
  250. END IF
  251. drawList = _TRUE
  252. EXIT DO'Exit the loop so we can draw
  253. END IF
  254. END SELECT
  255. END IF
  256. inc(x)'increment our row counter
  257. UNTIL x = numRows +1' or x = List.numRecords + 1'check all rows so do it again while mouse is down
  258. LONG IF drawList = _TRUE
  259. fn DrawList(List)
  260. END IF
  261. err = FN EventAvail(0,evnt)'allows time for system tasks and stop the spinning cursor in OSX
  262. WEND
  263. WhichString = List.newselect' + BUTTON(List.LScrollBtn) - 1'when the mouse is up this is our string
  264. Selected$ =STR#(List.STResNo,WhichString)
  265. END FN = Selected$'return it to whoever called
  266.  
  267.  
  268.  
  269. '~Initialize indivual lists
  270.  
  271. /*
  272. This is the place we set up the list.  You should define one global list record for each
  273. list you want to display.  Note that you can increase or decrease the number of columns you
  274. need to display and then set the width, font , size, style of the list and the individual 
  275. color of each column.  This example uses STR# resources for the data but it could just as easily
  276. be an array of any kind.   I chose the  -  character for the delimiter between columns and the ^ to
  277. denote what follows is an icon family resource.  You need to add these resources to your resource
  278. file.  Note the [] brackets necessary for arrays in records.  I use a User Item in PG for this demo
  279. to set the basic area for the list and then modify the height depending on the font chosen.  I also
  280. modify the last row to set it to the full right side of the list as it is drawn.  If you calculated
  281. the exact width needed for columns or did not use a PG object you could eliminate that step.
  282.  
  283. This shows how you could add all kinds of things to a list display.  More graphics, back colors for
  284. each cell etc.
  285.  
  286. */
  287.  
  288. clear LOCAL
  289. DIM as int WhichList,numRows,ht,CurRes
  290. DIM @r,g,b
  291. DIM @loop
  292. DIM as handle resHndl&
  293. dim @fontNum
  294. DIM fontName as str255
  295. '~'2
  296. LOCAL FN InitHelpTopicList
  297. '~'2
  298. FN pGgetObj(_MyCalendarHelp2Wnd,_HelpTopicList)'get our user item for the list
  299. HelpList.WhichString = 1
  300. HelpList.newselect   = 1
  301. HelpList.LScrollBtn  = _scrlBar1WClass39
  302. HelpList.ncols       = 1'the number of columns
  303. HelpList.STResNo     = _HelpListSTR'the resource number of the STR#
  304. HelpList.ListRect    = @gObjT'basic size of the list rectangle
  305. HelpList.colwd%[1]   = 200'width of each column
  306. HelpList.txtalign[1] = 0'alignment of individual columns
  307. 'GetFNum("Arial",fontNum)
  308. HelpList.fnt         = 3'the font for this list
  309. HelpList.sze         = 12'the size for this list
  310. HelpList.styl        = 0
  311. HelpList.delim$      = "-"'delimiter between cell data
  312. text HelpList.fnt ,HelpList.sze,HelpList.styl
  313. resHndl& = FN GETRESOURCE(_"STR#",_HelpListSTR)'Get a handle to the STR# resource we are using
  314. LONG IF resHndl&
  315. HelpList.numRecords = {[resHndl&]}'count the number of elements
  316. XELSE
  317. HelpList.numRecords = 0'problem - no handle - no elements
  318. END IF
  319. '~'2
  320. 'just adjust the overall rectangle if the one drawn in PG is not exactly a multiple of n rows
  321. '~'2
  322. numRows = (HelpList.ListRect.bottom-HelpList.ListRect.top)\(USR FONTHEIGHT)
  323. ht = USR FONTHEIGHT * numRows
  324. HelpList.ListRect.bottom = HelpList.ListRect.top + ht +2
  325. END FN
  326.  
  327.  
  328. CLEAR LOCAL
  329. DIM CurRes
  330. '~'2
  331. LOCAL FN ClickNoteScrollBtn'We clicked in the list
  332. '~'2
  333. WINDOW gWhichClass
  334. SELECT gWhichClass
  335. case _MyCalendarHelp2Wnd
  336. LONG IF gWhichButton = _scrlBar1WClass39
  337. fn DrawList(HelpList)
  338. END IF
  339. end select
  340. END FN
  341.  
  342.  
  343. clear local
  344. DIM as int  numRows
  345. '~'2
  346. Local Fn ViewAListItem(List AS ^ListRecord,selected,item)'view selected line or any line passed in item
  347. '~'2
  348. LONG IF selected <> _false'view the currently selected line
  349. scroll BUTTON List.LScrollBtn,List.newselect' + numRows
  350. xelse
  351. LONG IF item <> 0'or view a line passed in the var item
  352. List.newselect = item'and selected is set to _false
  353. SCROLL BUTTON List.LScrollBtn,item
  354. END IF
  355. END IF
  356. fn DrawList(List)
  357. END FN
  358.  
  359.  
  360.  
  361. '~':
  362.  
  363. "EndOfList"
  364.  
  365. DIM TheResponse,Temp$,TxResNo,teHndl&,CurRes,resref
  366. dim as handle resHndl&
  367. Dim sloc,Da$,Note$,resID%
  368. dim t as rect
  369. dim dashloc,slashloc,Dur,slashloc2
  370.  
  371.  
  372. SELECT gLongAction&
  373. '~'2
  374. CASE _mStart
  375. FN InitHelpTopicList
  376. '~'2
  377. CASE _oUserUpdate
  378. LONG IF gObjUserTp& = _"List"
  379. SELECT gWhichWindow
  380. CASE _MyCalendarHelp2Wnd
  381. FN DrawList(HelpList)
  382. END SELECT
  383. END IF
  384.  
  385. '~'2
  386.  
  387. '~'2
  388. CASE _btnLong
  389. FN ClickNoteScrollBtn
  390.  
  391. end select
  392.  
  393. '~'4
  394. IF 0 then return
  395.  
  396.  
  397.  
  398.  
  399.  
  400.